package com.BlogPark.controller;

import com.BlogPark.controller.exception.Code;
import com.BlogPark.controller.result.Result;
import com.BlogPark.pojo.DetailsUser;
import com.BlogPark.service.EditPersonalInformationService.EditPersonalInformationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @Auther: 传说
 * @Date: 08 - 18
 * 个人信息 编辑 响应
 */

@RestController
@RequestMapping("/PersonalInformation")
public class EditPersonalInformationController {
    @Autowired
    private EditPersonalInformationService editPersonalInformationService;

    //查询个人详细信息
    @GetMapping("/{id}")
    private Result select(@PathVariable Integer id){

        DetailsUser user = editPersonalInformationService.ViewPersonalInfo(id);
        if (user!=null){
            return new Result(Code.GET_OK,user,"查询成功");
        }
        return new Result(Code.GET_ERR,null,"查询失败");
    }

    //修改个人详细信息
    @PutMapping
    private Result update(@RequestBody DetailsUser user){

        Integer data = editPersonalInformationService.EditPersonalInfo(user);
        if(data>0){
            return new Result(Code.UPDATE_OK,user,"修改成功");
        }
        return new Result(Code.UPDATE_ERR,null,"修改失败");
    }
    //修改个人详细信息
    @GetMapping("/profilePhoto/{userId}")
    private Result getProfilePhoto(@PathVariable int userId){

        String data = editPersonalInformationService.getprofilePhoto(userId);
        if(data!=null){
            return new Result(Code.UPDATE_OK,data,"获取头像成功");
        }
        return new Result(Code.UPDATE_ERR,null,"获取头像失败");
    }




}
